package cn.wolfcode.utils;

import cn.wolfcode.constant.JwtClaimsConstant;
import cn.wolfcode.properties.JwtProperties;
import io.jsonwebtoken.Claims;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

@Component
@Slf4j
public class GeneralUtils {

    @Autowired
    JwtProperties jwtProperties;

    public String getPhone(HttpServletRequest request)  throws Exception {
        String token = request.getHeader(jwtProperties.getUserTokenName());
        Claims claims = JwtUtil.parseJWT(jwtProperties.getUserSecretKey(), token);
        return claims.get(JwtClaimsConstant.USER_ID).toString();
    }
}
